a=81**18-(81**8-1)*(9**8+1)//8-8
k=0
while a>0:
    if a%3==1:
        k+=1
    a=a//3
print(k)